Skip to content

fix(kotlin): add @Valid annotation for cascade validation#2593

Open
alexanderxfgl-bit wants to merge 1 commit into
asyncapi:masterfrom
alexanderxfgl-bit:fix/kotlin-valid-annotation
Open

fix(kotlin): add @Valid annotation for cascade validation#2593
alexanderxfgl-bit wants to merge 1 commit into
asyncapi:masterfrom
alexanderxfgl-bit:fix/kotlin-valid-annotation

Conversation

@alexanderxfgl-bit

Copy link
Copy Markdown

Description

The Kotlin ConstraintsPreset was missing the @Valid annotation for array, object, and reference properties, effectively disabling cascading validation. This is the same issue that was fixed for the Java generator in #2175.

Without @Valid, validation constraints on nested objects and array elements are never triggered, so invalid data in nested structures passes silently.

Changes

  • Add @Valid annotation (@get:Valid in Kotlin syntax) for ConstrainedArrayModel, ConstrainedObjectModel, and ConstrainedReferenceModel properties
  • Add javax.validation.Valid (or jakarta.validation.Valid when useJakarta: true) to imports
  • Add test case verifying @Valid is rendered for nested object and array properties
  • Update existing test snapshots to include new import

Example output

data class NestedClazz(
    @get:Valid
    val arrayProp: List<String>? = null,
    @get:Valid
    val objProp: ObjProp? = null,
)

Related issue

Fixes #2573

…ject/reference fields

The Kotlin ConstraintsPreset was missing the @Valid annotation for
array, object, and reference properties, which disabled cascading
validation. This is the same issue that was fixed for the Java
generator in asyncapi#2175.

Changes:
- Add @Valid annotation for ConstrainedArrayModel, ConstrainedObjectModel,
  and ConstrainedReferenceModel properties
- Add javax.validation.Valid (or jakarta.validation.Valid) import
- Add test case verifying @Valid is rendered for nested object and array props

Fixes asyncapi#2573
@netlify

netlify Bot commented Jun 27, 2026

Copy link
Copy Markdown

Deploy Preview for modelina canceled.

Name Link
🔨 Latest commit 95feaf4
🔍 Latest deploy log https://app.netlify.com/projects/modelina/deploys/6a3ff70a61084a0009510c59

@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Kotlin Constraints Preset omits @Valid annotation

2 participants